/**
* This file is part of OntoApplications (project linked with OntoCompoFramework)
*
* Copyright (C) 2011 -  Christian Brel
*
* @author   Main    Christian Brel
**/
package applications.staticmap.ui.lib;


import java.awt.Dimension;
import java.util.Observable;
import javax.swing.JComponent;
import javax.swing.JEditorPane;

import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;

import org.objectweb.fractal.fraclet.annotations.Component;
import org.objectweb.fractal.fraclet.annotations.Interface;
import org.objectweb.fractal.fraclet.annotations.Requires;

@Component(provides = {@Interface(name = "jEditorPaneItf", signature = ontocompo.api.swing.JEditorPaneItf.class), @Interface(name = "uicontainerservice", signature = ontocompo.api.UIContainerService.class), @Interface(name = "observer", signature = java.util.Observer.class), @Interface(name = "ontocompointrospection", signature = ontocompo.api.OntoCompoIntrospection.class)})
public class StaticMapResultPanel extends JEditorPane implements /*ContainerService,*/ ontocompo.api.swing.JEditorPaneItf, ontocompo.api.UIContainerService, java.util.Observer, ontocompo.api.OntoCompoIntrospection {

	private String uid;
	private org.objectweb.fractal.api.Component c;
	
	@Requires(name = "staticmapservice")
	private applications.staticmap.fc.api.StaticMapService staticmapservice;
	
	@Requires(name = "staticmapobservable")
	private ontocompo.api.Observable staticmapobservable;
	
	public StaticMapResultPanel() {
		super();
		this.uid = "applications.staticmap.ui.lib.StaticMapResultPanel";
		System.out.println(this.toString() + " created");
		//this.init();
	}
	
	public void init() {
		this.staticmapobservable.addObserver(this);

		HTMLEditorKit kit = new HTMLEditorKit();
        HTMLDocument htmlDoc = (HTMLDocument) kit.createDefaultDocument();
        this.setEditable(false);
        this.setContentType("text/html");
        this.setEditorKit(kit);
        this.setDocument(htmlDoc);
        
        Dimension d = new Dimension(490, 500);
        
        this.setMinimumSize(d);
        this.setPreferredSize(d);
        this.setMaximumSize(d);
        this.setSize(d);
	}
	
//	@Override
	public JComponent getComponentItSelf() {
		// TODO Auto-generated method stub
		return this;
	}

	@Override
	public String getUid() {
		// TODO Auto-generated method stub
		return this.uid;
	}

	@Override
	public void setUid(String uid) {
		// TODO Auto-generated method stub
		this.uid = uid;
	}
	
	public String toString() {
		return "BusinessDirectoryVisitCardPanel";
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		String mapContent = this.staticmapservice.getHtmlStaticMap();
		if(mapContent == null || mapContent == "") {
			return ;
		} else {
			this.update(mapContent);
		}
	}

	@Override
	public void update(Object o) {
		// TODO Auto-generated method stub
		String mapContent = (String) o;
		
		this.setText(mapContent);
		
		this.getParent().validate();
	}
	
	@Override
	public org.objectweb.fractal.api.Component getFractalComponent() {
		// TODO Auto-generated method stub
		return this.c;
	}

	@Override
	public void setFractalComponent(org.objectweb.fractal.api.Component c) {
		// TODO Auto-generated method stub
		this.c = c;
	}

}
